﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Numpad 000 Key</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="alternate" type="application/rss+xml" title="AutoHotkey Forum RSS" href="/forum/rss.php">
<link href="/docs/css/default.css" rel="stylesheet" type="text/css">
<link href="/docs/css/print.css" rel="stylesheet" type="text/css" media="print">
</head>
<body>

<h6>Numpad 000 Key</h6>

<p> This example script makes the special 000 key that appears on certain
 keypads into an equals key.  You can change the action by replacing the
 &ldquo;Send, =&rdquo; line with line(s) of your choice.
</p>
<p><a href="Numpad000.ahk">Download This Script</a> &nbsp;| &nbsp;<a href="index.htm">Other Sample Scripts</a> &nbsp;| &nbsp;<a href="http://www.autohotkey.com">Home</a></p>

<pre class="NoIndent">#MaxThreadsPerHotkey 5  <em>; Allow multiple threads for this hotkey.</em>
$Numpad0::
#MaxThreadsPerHotkey 1
<em>; Above: Use the $ to force the hook to be used, which prevents an</em>
<em>; infinite loop since this subroutine itself sends Numpad0, which</em>
<em>; would otherwise result in a recursive call to itself.</em>
SetBatchLines, 100 <em>; Make it run a little faster in this case.</em>
DelayBetweenKeys = 30 <em>; Adjust this value if it doesn't work.</em>
if A_PriorHotkey = %A_ThisHotkey%
{
    if A_TimeSincePriorHotkey &lt; %DelayBetweenKeys%
    {
        if Numpad0Count =
            Numpad0Count = 2 <em>; i.e. This one plus the prior one.</em>
        else if Numpad0Count = 0
            Numpad0Count = 2
        else
        {
            <em>; Since we're here, Numpad0Count must be 2 as set by</em>
            <em>; prior calls, which means this is the third time the</em>
            <em>; the key has been pressed. Thus, the hotkey sequence</em>
            <em>; should fire:</em>
            Numpad0Count = 0
            Send, = <em>; ******* This is the action for the 000 key</em>
        }
        <em>; In all the above cases, we return without further action:</em>
        CalledReentrantly = y
        return
    }
}
<em>; Otherwise, this Numpad0 event is either the first in the series</em>
<em>; or it happened too long after the first one (e.g. perhaps the</em>
<em>; user is holding down the Numpad0 key to auto-repeat it, which</em>
<em>; we want to allow).  Therefore, after a short delay -- during</em>
<em>; which another Numpad0 hotkey event may re-entrantly call this</em>
<em>; subroutine -- we'll send the key on through if no reentrant</em>
<em>; calls occurred:</em>
Numpad0Count = 0
CalledReentrantly = n
<em>; During this sleep, this subroutine may be reentrantly called</em>
<em>; (i.e. a simultaneous &quot;thread&quot; which runs in parallel to the</em>
<em>; call we're in now):</em>
Sleep, %DelayBetweenKeys%
if CalledReentrantly = y <em>; Another &quot;thread&quot; changed the value.</em>
{
    <em>; Since it was called reentrantly, this key event was the first in</em>
    <em>; the sequence so should be suppressed (hidden from the system):</em>
    CalledReentrantly = n
    return
}
<em>; Otherwise it's not part of the sequence so we send it through normally.</em>
<em>; In other words, the *real* Numpad0 key has been pressed, so we want it</em>
<em>; to have its normal effect:</em>
Send, {Numpad0}
return
</pre>
</body>
</html>
